package cn.java78.springboot.myschool.pojo;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

/**
 * @author oldliu
 * @since 1.0
 */
public class Page<T> implements Serializable {
    //当前页号
    private int pageNo;
    //页大小
    private int pageSize;
    //总条数
    private int totalElements;

    //当前页的数据
    private List<T> datas=new ArrayList<>();
    public Page(){

    }

    public Page(int pageNo, int pageSize, int totalElements, List<T> datas) {
        this.pageNo = pageNo;
        this.pageSize = pageSize;
        this.totalElements = totalElements;
        this.datas = datas;
    }

    //这个方法算总页数。
    public int getTotalPages(){
        if(pageSize<=0)
            throw  new IllegalArgumentException("页大小居然是0");

        return totalElements/pageSize+(totalElements%pageSize==0?0:1);
    }

    public int getPageNo() {
        return pageNo;
    }

    public void setPageNo(int pageNo) {
        this.pageNo = pageNo;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalElements() {
        return totalElements;
    }

    public void setTotalElements(int totalElements) {
        this.totalElements = totalElements;
    }

    public List<T> getDatas() {
        return datas;
    }

    public void setDatas(List<T> datas) {
        this.datas = datas;
    }
}
